package org.casper.outofmemory;

import javassist.CannotCompileException;
import javassist.ClassPool;

public class TestPerm {

	/**
	 * 演示异常:java.lang.OutOfMemoryError Perm Space 运行参数:-verbose:gc
	 * -XX:MaxPermSize=128m 解决思路:-XX:PermSize=10M -XX:MaxPermSize=4g
	 */
	public static void main(String[] args) throws CannotCompileException,
			RuntimeException {
		for (int i = 0; i < 100_000_000; i++) {
			generateClass("myclass" + i);
		}
	}

	@SuppressWarnings("rawtypes")
	private static Class generateClass(String className)
			throws CannotCompileException, RuntimeException {
		ClassPool pool = ClassPool.getDefault();
		return pool.makeClass(className).toClass();
	}

}
